<!--添加种类-->
<template>
    <div>
        <el-dialog title="添加种类" :visible.sync="dialogVisible" width="30%"
                :close="close"
                :before-close="close">

            <el-form ref="form" :model="form" label-width="80px">
                <el-form-item label="种类名称">
                    <el-input v-model="form.typeName"></el-input>
                </el-form-item>
                <el-form-item label="默认">
                    <el-select v-model="form.isDefault">
                        <el-option v-for="(item, i) in default__" :key="i" :label="item.label" :value="item.value"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>

            <span slot="footer" class="dialog-footer">
                <el-button @click="close">取 消</el-button>
                <el-button type="primary" @click="addType">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import API from '@/api/api';
export default {
    name: "TypeAdd",
    data() {
        return {
            dialogVisible: true,
            form: {
                typeName: '',
                isDefault: 0,
            },
            default__: [
                {label: '是', value: 1},
                {label: '否', value: 0}
            ]
        }
    },
    methods: {
        close() {
            this.$emit("close");
        },
        addType() {
            let url = API.type.add;
            let param = this.form;
            this.$post(url, param).then( res => {
                let data = res.data;
                if (data.success) {
                    this.$message.success("添加成功");
                    this.close();
                } else {
                    this.$message.error(data.msg);
                }
            }).catch( err => {
                this.$message.error("请求失败!");
            })
        }
    }
}
</script>

<style scoped>

</style>
